package com.piece.test;

import com.piece.core.framework.util.security.SecurityUtil;
import com.piece.core.framework.util.security.coder.Base64Coder;
import com.piece.core.framework.util.security.coder.MD5Coder;
import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

public class FrameworkTest {

    /**
     * 生成客户端加密信息
     */
    @Test
    public void generateClientPwd() {
        PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String authorization = Base64Coder.encode("piece-admin-service:piece-admin");
        System.out.println(authorization);
        String encode = passwordEncoder.encode("piece-admin");
        System.out.println(encode);
        System.out.println(passwordEncoder.matches("piece-admin", encode));
        authorization = Base64Coder.encode("piece-vue-service:piece-vue");
        System.out.println(authorization);
        encode = passwordEncoder.encode("piece-vue");
        System.out.println(encode);
        System.out.println(passwordEncoder.matches("piece-vue", encode));
    }

    /**
     * 生成用户账号密码
     */
    @Test
    public void generateUserPwd() {
        String name = "admin";
        String pwd = "admin123";
        String salt = SecurityUtil.randomSalt();
        System.out.println("salt:" + salt);
        System.out.println(MD5Coder.decode(name + pwd + salt));
        name = "demo";
        pwd = "demo123";
        salt = SecurityUtil.randomSalt();
        System.out.println("salt:" + salt);
        System.out.println(MD5Coder.decode(name + pwd + salt));
        name = "public";
        pwd = "public123";
        salt = SecurityUtil.randomSalt();
        System.out.println("salt:" + salt);
        System.out.println(MD5Coder.decode(name + pwd + salt));
    }
}
